<template>
  <div class="home">
    <h2>首页</h2>

    <div class="content-section">
      <h3>页面缓存测试</h3>
      <p>这个页面使用了 keep-alive 缓存，输入内容在页面切换时会被保留。</p>

      <div class="input-demo">
        <el-input v-model="input" placeholder="输入内容测试缓存" style="width: 300px" />
        <p class="input-status">当前输入：{{ input }}</p>
      </div>

      <div class="navigation">
        <el-button type="primary" @click="handleClick"> 跳转到关于页面 </el-button>
        <el-button type="success" @click="goToApiTest"> 🎭 API延迟测试 </el-button>
      </div>
    </div>

    <div class="info-section">
      <h3>应用功能</h3>
      <ul>
        <li>✅ 页面缓存 (keep-alive)</li>
        <li>✅ 路由管理</li>
        <li>✅ API请求封装</li>
        <li>✅ Pinia状态管理</li>
        <li>✅ Mock数据延迟响应</li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

// 为组件定义明确的名称，供 keep-alive 使用
defineOptions({
  name: 'Home',
})

const router = useRouter()
const input = ref('')

const handleClick = () => {
  router.push('/about')
}

const goToApiTest = () => {
  router.push('/api-test')
}
</script>

<style scoped>
.home {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

h2 {
  color: #409eff;
  margin-bottom: 30px;
  text-align: center;
  font-size: 2rem;
}

h3 {
  color: #606266;
  margin-bottom: 15px;
  font-size: 1.2rem;
}

.content-section {
  margin-bottom: 40px;
  padding: 25px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #409eff;
}

.input-demo {
  margin: 20px 0;
}

.input-status {
  margin-top: 10px;
  color: #666;
  font-size: 14px;
}

.navigation {
  margin-top: 20px;
}

.navigation .el-button {
  margin-right: 12px;
}

.info-section {
  padding: 25px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.info-section ul {
  list-style: none;
  padding: 0;
}

.info-section li {
  padding: 8px 0;
  color: #606266;
  font-size: 15px;
  border-bottom: 1px solid #f0f0f0;
}

.info-section li:last-child {
  border-bottom: none;
}

@media (max-width: 768px) {
  .home {
    padding: 15px;
  }

  .navigation .el-button {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    margin-right: 0;
  }
}
</style>
